﻿namespace DesignPattern.com.mediator {
    public class MediatorImpl :Mediator {
        private ColleagueA ca;
        private ColleagueB cb;

        public override void setColleagueA(ColleagueA ca){
            this.ca = ca;
        }

        public override void setColleagueB(ColleagueB cb){
            this.cb = cb;
        }
        
        /// <summary>
        /// 接受来自colleague的通知
        /// </summary>
        /// <param name="col"></param>
        /// <param name="msg"></param>
        public override void sendMsg(Colleague col, string msg){

            //收到ca的通知的时候向cb发送请求
            if (col == ca){
                cb.request(msg);
            }
            
            //收到cb的通知的时候向ca发送请求
            else if (col == cb){
                ca.request(msg);
            }
        }
    }
}